home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / WindowAids.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  6.3 KB  |  296 lines  |  [TEXT/KAHL]

  1. /* WindowAids.c */    /*    C14 Calculator */
  2.  
  3.  
  4. #include "Globals.h"
  5.  
  6.  
  7. #include "WindowAids.h"
  8. #include <Lists.h>
  9.  
  10. short        textJust;        /* set by SetWFont */
  11.  
  12. typedef struct {
  13.         Handle            reserved;
  14.         Rect            displayRect;
  15.         Byte            itemKind;
  16.         Byte            dataLen;
  17. } ItemTemplate, *ItemTPtr;
  18.  
  19. #define ItemTBaseSize    sizeof (ItemTemplate)
  20.  
  21.  
  22. typedef struct {
  23.         short            maxItem;
  24.         ItemTemplate    items;    /* repeated */
  25. } WitlTemplate, *WitlTPtr, **WitlTHndl;
  26.  
  27. void    WindowAidsSeg()    {}
  28.  
  29. /*----------*/
  30. void    GetWRect        (short            itemNr,
  31.                          Rect            *itemRect)
  32. {
  33.     WitlTHndl        witlHandle;
  34.     ItemTPtr        wItemPtr;
  35.     short            I;
  36.     short            dataSize;
  37.  
  38.     SetRect (itemRect, 0, 0, 16, 16);
  39.     witlHandle = (WitlTHndl) cur->witlHandle;
  40.     if ((witlHandle != NULL)
  41.     &&  (itemNr <= (**witlHandle).maxItem + 1) ) {
  42.         wItemPtr = &(**witlHandle).items;
  43.         for (I = 1; I <= itemNr - 1; I++) {
  44.             dataSize = wItemPtr->dataLen + (wItemPtr->dataLen & 1);
  45.             wItemPtr = (ItemTPtr) (((Ptr)wItemPtr) + (ItemTBaseSize + dataSize));
  46.         } /*for*/
  47.         *itemRect = wItemPtr->displayRect;
  48.     }
  49. } /* GetWRect */
  50.  
  51. typedef struct {
  52.         short            header;
  53.         short            offset;
  54. } ictbEntry, *ictbEntryPtr;
  55.  
  56.     
  57. typedef struct {
  58.         ictbEntry        item [5000];
  59. } WictTemplate, *WictTPtr, **WictTHndl;
  60.  
  61. typedef struct {
  62.         short            fontNum;
  63.         Style            typeStyle;
  64.         SignedByte        just;        /* AppMaker adition */
  65.         short            typeSize;
  66.         RGBColor        fgColor;
  67.         RGBColor        bgColor;
  68.         short            xferMode;
  69. } StyleData, *StyleDataPtr;
  70.  
  71.  
  72. /* set transfer mode */
  73. #define doXferMode    0x4000
  74.  
  75.  
  76.  
  77. /* set font by name */
  78. #define doByName    0x8000
  79.  
  80.  
  81. /*----------*/
  82. void    SetWFont        (short            itemNr)
  83. {
  84.     WictTHndl        wictHandle;
  85.     Ptr                wictPtr;
  86.     ictbEntryPtr    itemPtr;
  87.     short            header;
  88.     short            offset;
  89.     StyleDataPtr    dataPtr;
  90.     StyleData        data;
  91.     StringPtr        fontPtr;
  92.     Str255            fontName;
  93.  
  94.     wictHandle = (WictTHndl) cur->wictHandle;
  95.     if (wictHandle != nil) {
  96.         wictPtr = (Ptr) &(**wictHandle);
  97.         itemPtr = &(**wictHandle).item [itemNr - 1];
  98.         header = itemPtr->header;
  99.         offset = itemPtr->offset;
  100.         dataPtr = (StyleDataPtr) (wictPtr + offset);
  101.         data = *dataPtr;
  102.         if ((header & doFont) == 0) {
  103.             data.fontNum = 0;
  104.         } else {
  105.             if ((header & doByName) != 0) {
  106.                 fontPtr = (StringPtr) (wictPtr + data.fontNum);
  107.                 BlockMove (fontPtr, &fontName, 256);
  108.                 GetFNum (fontName, &data.fontNum);
  109.             }
  110.         }
  111.         if ((header & doFace) == 0) {
  112.             data.typeStyle = 0;
  113.         }
  114.         if ((header & doSize) == 0) {
  115.             data.typeSize = 0;
  116.         }
  117.         if ((header & doXferMode) == 0) {
  118.             data.xferMode = srcCopy;
  119.         }
  120.         TextFont (data.fontNum);
  121.         TextFace (data.typeStyle);
  122.         TextMode (data.xferMode);
  123.         TextSize (data.typeSize);
  124.         textJust = data.just;
  125.     }
  126. } /* SetWFont */
  127.     
  128.  
  129. /*----------*/
  130. WindowPtr GetWindow        (short            windowID)
  131. {
  132.     if (sysConfig.hasColorQD) {
  133.         return (GetNewCWindow (windowID, NULL, (WindowPtr) -1L));
  134.     } else {
  135.         return (GetNewWindow (windowID, NULL, (WindowPtr) -1L));
  136.     }
  137. } /* GetWindow */
  138.  
  139. /*----------*/
  140. ListHandle NewV1List    (Rect            bounds,
  141.                           WindowPtr        parentWindow)
  142. {
  143.     Rect            listBounds;
  144.     Rect            dataBounds;
  145.     Point            cSize;
  146.     ListHandle        list;
  147.  
  148.     listBounds = bounds;
  149.     /*listBounds.right = listBounds.right - 15;*/    /*for scroll bar*/
  150.     SetRect (&dataBounds, 0, 0, 1, 0);    /*one column, no rows*/
  151.     SetPt (&cSize, listBounds.right - listBounds.left, 0);
  152.     list = LNew    (&listBounds,    /*dialog item's box*/
  153.                  &dataBounds,    /*one column, no rows*/
  154.                  cSize,            /*cell size: full width, standard height*/
  155.                  0,                /*procid - standard text list*/
  156.                  parentWindow,    /*parent window*/
  157.                  false,            /*draw it*/
  158.                  false,            /*has no grow*/
  159.                  false,            /*no horizontal scroll*/
  160.                  false);            /*vertical scroll*/
  161.     (**list).selFlags = lOnlyOne + lNoNilHilite;
  162.     return (list);
  163. } /*NewV1List*/
  164.  
  165. /*----------*/
  166. ListHandle NewV1SList    (Rect            bounds,
  167.                           WindowPtr        parentWindow)
  168. {
  169.     Rect            listBounds;
  170.     Rect            dataBounds;
  171.     Point            cSize;
  172.     ListHandle        list;
  173.  
  174.     listBounds = bounds;
  175.     listBounds.right = listBounds.right - 15;    /*for scroll bar*/
  176.     SetRect (&dataBounds, 0, 0, 1, 0);    /*one column, no rows*/
  177.     SetPt (&cSize, listBounds.right - listBounds.left, 0);
  178.     list = LNew    (&listBounds,    /*dialog item's box*/
  179.                  &dataBounds,    /*one column, no rows*/
  180.                  cSize,            /*cell size: full width, standard height*/
  181.                  0,                /*procid - standard text list*/
  182.                  parentWindow,    /*parent window*/
  183.                  false,            /*draw it*/
  184.                  false,            /*has no grow*/
  185.                  false,            /*no horizontal scroll*/
  186.                  true);            /*vertical scroll*/
  187.     (**list).selFlags = lOnlyOne + lNoNilHilite;
  188.     return (list);
  189. } /*NewV1SList*/
  190.  
  191.  
  192. /*----------*/
  193. Boolean    GetListChoice    (short            *choice,
  194.                          ListHandle        list)
  195. {
  196.     Boolean            result;
  197.     Cell            selectedCell;
  198.  
  199.     SetPt (&selectedCell, 0, 0);
  200.     if (LGetSelect (true, &selectedCell, list)) {
  201.         *choice = selectedCell.v;
  202.         result = true;
  203.     } else {
  204.         *choice = -1;
  205.         result = false;
  206.     }
  207.  
  208.     return (result);
  209. } /*GetListChoice*/
  210.  
  211. /*----------*/
  212. void    SetListChoice    (short            choice,
  213.                          ListHandle        list)
  214. {
  215.     Cell            selectedCell;
  216.  
  217.     SetPt (&selectedCell, 0, choice);
  218.     LSetSelect (true, selectedCell, list);
  219. } /*SetListChoice*/
  220.  
  221. /*----------*/
  222. void    GetListRow        (Str255            data,
  223.                          short            index,
  224.                          ListHandle        list)
  225. {
  226.     Cell            selectedCell;
  227.     short            dataLen;
  228.  
  229.     SetPt (&selectedCell, 0, index);
  230.     dataLen = 255;        /*var parameter to LGetCell*/
  231.     LGetCell (&data [1], &dataLen, selectedCell, list);
  232.     data [0] = (char) dataLen;
  233. } /*GetListRow*/
  234.  
  235. /*----------*/
  236. void    SetListRow        (Str255            data,
  237.                          short            index,
  238.                          ListHandle        list)
  239. {
  240.     Cell            selectedCell;
  241.  
  242.     SetPt (&selectedCell, 0, index);
  243.     LSetCell (&data [1], data [0], selectedCell, list);
  244. } /*SetListRow*/
  245.  
  246. /*----------*/
  247. void AddToList        (Str255            data,
  248.                      ListHandle        list)
  249. {
  250.     short            newRow;
  251.     
  252.     #define maxint    32767
  253.  
  254.     newRow = LAddRow (1, maxint, list);
  255.     SetListRow (data, newRow, list);
  256. } /*AddToList*/
  257.  
  258. /*----------*/
  259. void DrawList    (ListHandle        list)
  260. {
  261.     PenState        savePen;
  262.     Rect            frame;
  263.  
  264.     GetPenState (&savePen);
  265.     PenNormal ();
  266.     frame = (**list).rView;
  267.     InsetRect (&frame, -1, -1);
  268.     FrameRect (&frame);
  269.     SetPenState (&savePen);
  270.     LUpdate ((**list).port->visRgn, list);
  271. } /*DrawList*/
  272.  
  273.  
  274. /*----------*/
  275. void    EnableControl    (ControlHandle    theControl,
  276.                          Boolean        active)
  277. {
  278.     if (theControl != NULL) {
  279.         if (active) {
  280.             HiliteControl (theControl, 0);
  281.         } else {
  282.             HiliteControl (theControl, 255);
  283.         }
  284.     }
  285. } /*EnableControl*/
  286.  
  287.  
  288. /*----------*/
  289. /* for backwards compatibility:*/
  290. /*----------*/
  291. void    HiliteScroll    (ControlHandle    scroll,
  292.                          Boolean        active)
  293. {
  294.     EnableControl (scroll, active);
  295. } /*HiliteScroll*/
  296.